from ATS.instrumentDriver.IVGeneralFunc import IVGeneralFunc_B2900A as IVGeneralFunc
from ATS.globaldata import setglobal
from ATS.instrumentDriver import InstCom

from ATS.util import constant
import os

setglobal.set_globals(IVGeneralFunc, 'IVGeneralFunc', locals().copy())


def GeneralTest(Sweep, Step, Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq, Meas_Pro, Common):
    IVGeneralFunc.init(Sweep, Step, Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq, Meas_Pro,
                       Common)
    IVGeneralFunc.setup(Sweep, Step, Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq, Meas_Pro,
                        Common)
    if Common["gs_flag"] == 0:
        IVGeneralFunc.srcmeassample(Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq, Meas_Pro,
                                    Common)
    else:
        IVGeneralFunc.srcmeas(Sweep, Step, Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq,
                              Meas_Pro, Common)


# InstCom.getinstconfig(os.path.join(constant.RCF_PATH, "online.rcf"))
# print(InstCom.inst_dict)
Sweep = {}
Step = {}
Bias = {"SMU1": (1, 1), "SMU2": (2, 1)}
Open = {}
Meas_Range = {"SMU1": (1, 20, 1), "SMU2": (1, 1e-10, 0)}
Src_Range = {"SMU1": (1, 20, 1), "SMU2": (1, 20, 1)}
Compliance = {"SMU1": (0.1, 0), "SMU2": (0.1, 0)}
Remote_Sense = {"SMU1": 0, "SMU2": 0}
# Meas_Seq = {"SMU1":(1,["V_Hi(1)","V_Hi(2)","V_Hi(3)"]),"SMU2":(0,["I_Lo(1)","I_Lo(2)","I_Lo(3)"])}
Meas_Seq = {"SMU1": (1, ["V_Hi"])}
Meas_Pro = {"SMU2": ["V_Lo"]}
Common = {"gs_flag": 0, "avg_num": 10, "sample_pts": 11, "time_stamp": 1, "stop_comp": 0, "NPLC": 1, "hold_time": 0.5,
          "delay_time": 0.01, "swp_pts": 11, "step_pts": 1}

#    Sweep = {"SMU1":([0,0,5],1)}
#    Step = {"SMU2":([1,3],1)}
#    Bias = {}
#    Open = {}
#    Meas_Range = {"SMU1":(1,20,1),"SMU2":(1,1e-10,0)}
#    Src_Range = {"SMU1":(0,20,1),"SMU2":(1, 20 ,1)}
#    Compliance = {"SMU1":(0.1,0), "SMU2":(0.1,0)}
#    Remote_Sense = {"SMU1":0, "SMU2":0}
#    #Meas_Seq = {"SMU1":(1,["V_Hi(1)","V_Hi(2)","V_Hi(3)"]),"SMU2":(0,["I_Lo(1)","I_Lo(2)","I_Lo(3)"])}
#    Meas_Seq = {"SMU1":(2,["V_Hi(1)","I_Hi(1)","V_Hi(2)","I_Hi(2)","V_Hi(3)","I_Hi(3)"])}
#    Meas_Pro = {"SMU2":["V_Lo(1)","V_Lo(2)", "V_Lo(3)"]}
#    Common={"gs_flag":0, "sample_pts":11, "time_stamp":1, "stop_comp":0, "NPLC":1,"hold_time":0.5,"delay_time":0.01,"swp_pts":11, "step_pts":3}
#    Sweep = {"SMU1":([0,0,5],1)}
#    Step = {"SMU3":([1,3],1)}
#    Bias = {"SMU2":(2.5,1)}
#    Open = {}
#    Meas_Range = {"SMU1":(1,20,1),"SMU3":(1,1e-10,0)}
#    Src_Range = {"SMU1":(1,20,1),"SMU2":(1, 20 ,1),"SMU3":(1, 20 ,1)}
#    Compliance = {"SMU1":(0.1,0), "SMU2":(0.1,0), "SMU3":(0.1,0)}
#    Remote_Sense = {"SMU1":0, "SMU2":0, "SMU3":0}
#    #Meas_Seq = {"SMU1":(1,["V_Hi(1)","V_Hi(2)","V_Hi(3)"]),"SMU2":(0,["I_Lo(1)","I_Lo(2)","I_Lo(3)"])}
#    Meas_Seq = {"SMU1":(2,["V_Hi(1)","I_Hi(1)","V_Hi(2)","I_Hi(2)","V_Hi(3)","I_Hi(3)"])}
#    Meas_Pro = {"SMU2":["V_Lo(1)","V_Lo(2)", "V_Lo(3)"],"SMU3":["V_Lolo(1)","V_Lolo(2)", "V_Lolo(3)"]}
#    Common={"time_stamp":1, "stop_comp":0, "NPLC":1,"hold_time":0.5,"delay_time":0.01,"swp_pts":11, "step_pts":3}
GeneralTest(Sweep, Step, Bias, Open, Meas_Range, Src_Range, Compliance, Remote_Sense, Meas_Seq, Meas_Pro, Common)
